import MessageHandler from "@runtime/module/Handler/MessageHandler";
import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import LabelComponent from "@runtime/UnityEngineBridge/LabelComponent";

/**
 * 标签刷新消息
 */
export default class LabelUpdateMessageHandler extends MessageHandler<ClientMessage.LabelUpdateMessage> {
  protected async RunAsync(message: ClientMessage.LabelUpdateMessage): Promise<void> {
    // console.log(message.Informations, '刷新的信息+++++++');
    // MenuIndexData.Default.LabelDataList.value = message.Informations
    message.Informations.forEach((item) => {
      LabelComponent.Default.labelDataList.value.forEach((j) => {
        if (item.InstanceId == j.InstanceId) {
          j.ViewportPointX = item.ViewportPointX;
          j.ViewportPointY = item.ViewportPointY;
        }
      });
      LabelComponent.Default.OptionLabel.value.forEach((j) => {
        if (item.InstanceId == j.InstanceId) {
          j.ViewportPointX = item.ViewportPointX;
          j.ViewportPointY = item.ViewportPointY;
        }
      });
    });
    for (const information of message.Informations) {
      LabelComponent.Default.Update(information);
    }
  }
}
